<template>
    <aside class="layout-asides" :class="{ active: activeTab === 'asides'}">
        <div class="flex flex-col justify-between h-full">
            <el-scrollbar class="scrollbar">
                <div class="navigation">
                    <template v-for="(item, index) in diyData['nav']">
                        <div
                            v-if="item.isEnable"
                            :key="index"
                            class="nav-item"
                            :class="{ active: index === 0 }"
                        >
                            <el-image
                                v-if="index === 0"
                                :src="toAbsoluteUrl(item.selected)"
                                :lazy="true"
                                class="w-[24px] h-[24px]"
                            />
                            <el-image
                                v-else
                                :src="toAbsoluteUrl(item.unselected)"
                                :lazy="true"
                                class="w-[24px] h-[24px]"
                            />
                            <span class="mt-[6px] text-sm leading-4">{{ item.name }}</span>
                        </div>
                    </template>
                </div>
            </el-scrollbar>
            <div class="submenu">
                <template v-for="(item, index) in diyData['menu']">
                    <div v-if="item.isEnable" class="menu-item" :key="index">
                        <el-image
                            v-if="item.unselected"
                            :src="toAbsoluteUrl(item.unselected)"
                            :lazy="true"
                            class="w-[22px] h-[22px] mb-1.5"
                        />
                        <span class="text-xs">{{ item.name }}</span>
                    </div>
                </template>
            </div>
        </div>
    </aside>
</template>

<script setup lang="ts">
import type { AsidesType, AsidesItemType } from '../index.ts'
import useAppStore from '@/stores/modules/app'

defineProps({
    activeTab: {
        type: String,
        default: ''
    },
    diyData: {
        type: Object,
        default: () => ({
            nav: [] as AsidesItemType[],
            menu: [] as AsidesItemType[]
        } as AsidesType)
    }
})

const { toAbsoluteUrl } = useAppStore()
</script>

<style scoped lang="scss">
.layout-asides {
    display: flex;
    justify-content: stretch;
    width: auto;
    height: 100%;
    background-color: var(--el-bg-color);
    cursor: pointer;
    border: 1px solid transparent;
    &.active {
        border: 1px dashed var(--el-color-primary);
    }
    .scrollbar {
        width: 90px;
        height: 100%;
        :deep(.el-scrollbar__view) {
            height: 100%;
        }
    }
    .navigation {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 10px 0;
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 64px;
            height: 64px;
            margin-bottom: 15px;
            color: var(--el-text-color-regular);
            text-align: center;
            border-radius: 6px;
            &.active {
                color: var(--el-color-primary);
                background-color: rgb(206 206 206 / 40%);
            }
            &:hover {
                cursor: pointer;
                background-color: rgb(206 206 206 / 30%);
            }
        }
    }
    .submenu {
        .menu-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-between;
            //height: 66px;
            padding: 10px 15px;
            color: var(--el-text-color-regular);
            &:hover {
                color: var(--el-color-primary) !important;
                cursor: pointer;
            }
        }
    }
}
</style>